﻿using System;
using System.Linq.Expressions;
using System.Collections.Generic;

namespace PMngr.Main
{
    public class UnitModel
    {
        public static readonly IDictionary<string, string> Dict = new Dictionary<string, string>
           {
               {"Id", "Id"},
               {"Name", "名称"},
               {"Subsidiary", "下属单位"},
               {"IsValid", "是否有效"},
               {"Address", "地址"},
               {"Contact", "联系人"},
               {"ContactTel", "联系电话"},
               {"CreateDate", "创建日期"},            
               {"Description", "描述"},
               {"UnitTypeCode", "UnitTypeCode"},
               {"UnitType", "单位区域"},
               {"UnitKind", "单位性质"},
               {"Capacity", "编制数"},
               {"SuperUnit", "主管部门"}
           };

        public UnitModel()
        {
            Id = 0;
            Name = String.Empty;
            Subsidiary = 0;
            IsValid = true;
            Address = String.Empty;
            Contact = String.Empty;
            ContactTel = String.Empty;
            CreateDate = DateTime.Now;
            Description = String.Empty;
            UnitTypeCode = 0;
            UnitType = String.Empty;
            UnitKind = String.Empty;
            Capacity = 0;
            SuperUnit = String.Empty;
        }

        public int Id { get; set; }
        public string Name { get; set; }
        public int Subsidiary { get; set; }
        public bool IsValid { get; set; }
        public string Address { get; set; }
        public string Contact { get; set; }
        public string ContactTel { get; set; }
        public DateTime CreateDate { get; set; }
        public string Description { get; set; }
        public int UnitTypeCode { get; set; }
        public string UnitType { get; set; }
        public string UnitKind { get; set; }
        public int Capacity { get; set; }
        public string SuperUnit { get; set; }
        // get property native name
        [System.Diagnostics.DebuggerStepThrough]
        public static string GetPropertyName<T>(Expression<Func<UnitModel, T>> func)
        {
            return GetPropertyImpl(func);
        }
        // get property friendly name
        [System.Diagnostics.DebuggerStepThrough]
        public static string GetFriendlyName<T>(Expression<Func<UnitModel, T>> func)
        {
            var name = GetPropertyImpl(func);
            return name != null ? Dict[name] : null;
        }
        [System.Diagnostics.DebuggerStepThrough]
        private static string GetPropertyImpl(LambdaExpression expression)
        {
            var member = expression.Body as MemberExpression;
            return member != null ? member.Member.Name : null;
        }
    }
}
